package com.synergy.stockflow.exception;


import com.synergy.stockflow.constant.ResultCode;
import lombok.Getter;

/**
 * 自定义业务异常类
 */
public class BusinessException extends RuntimeException {

    // Getter 方法
    @Getter
    private final int code;
    private final String message;
    @Getter
    private final Object data;

    public BusinessException(int code, String message) {
        this(code, message, null);
    }

    public BusinessException(int code, String message, Object data) {
        super(message); // 调用父类构造方法，便于日志打印
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public BusinessException(ResultCode resultCode) {
        this(resultCode.value(), resultCode.getDesc());
    }

    public BusinessException(ResultCode resultCode, Object data) {
        this(resultCode.value(), resultCode.getDesc(), data);
    }

    @Override
    public String getMessage() {
        return message;
    }

}